package com.xmb.common.entity.structure;

public class Result<T> {

    private String errMsg;

    private Integer code;

    private T result;

    private static final int successCode = 200;

    private static final int authFailCode = 13;

    private static final int errorCode = -1;


    public static <T> Result<T> success(T result) {
        return build(result, "", successCode);
    }

    public static <T> Result<T> success(T result, String msg) {
        return build(result, msg, successCode);
    }

    public static <T> Result reAuthenticate() {
        return build("", "用户不存在,重新认证", authFailCode);
    }

    public static <T> Result<T> error(T result, String msg, Integer stat) {
        return build(result, msg, stat);
    }

    public static <T> Result<T> error(String msg) {
        return build(null, msg, 2);
    }

    public static <T> Result<T> build(T result, String errMsg, Integer code) {
        Result<T> b = new Result<T>();
        b.setCode(code);
        b.setErrMsg(errMsg);
        b.setResult(result);
        return b;
    }



    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
